package com.example.demo.client2;

import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Component;
import org.apache.cxf.endpoint.Client;

/**
 * @Description
 * @Author youxin
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2022/2/23
 */
@Component
public class UserInfoApiClient {
    private static final String USERNAME = "interface01";
    private static final String PASSWORD = "dtinsure123456";
    private static final String ADDRESS = "https://fkuat.dtinsure.com:8100/sap/bc/srt/rfc/sap/zws_stu_get_md/100/zws_stu_get_md/zws_stu_get_md";

    /**
     * 使用动态代理
     * @param id
     * @throws Exception
     */
    public void getUserInfoByIdWithDynamic(Long id) throws Exception {
        JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client = clientFactory.createClient(ADDRESS);
        client.getOutInterceptors().add(new ClientLoginInterceptor(USERNAME, PASSWORD));
        Object[] userInfos = client.invoke("ZfmRfcGetMd", id);
        String userInfo = userInfos[0].toString();
        System.out.println(userInfo);
    }
}
